/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.excesys.exsecs.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.excesys.exsecs.admin.api.entity.ControlLog;
import com.excesys.exsecs.admin.mapper.ControlLogMapper;
import com.excesys.exsecs.admin.service.ControlLogService;
import com.excesys.exsecs.common.security.util.SecurityUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 业务管理系统操作日志
 *
 * @author luxinchao
 * @date 2023-02-16 14:55:29
 */
@Service
public class ControlLogServiceImpl extends ServiceImpl<ControlLogMapper, ControlLog>
		implements ControlLogService {


	@Override
	public boolean saveControlLog(String tracedId, String operRecord, String result, String serviceModule,
								  String operBy) {
		ControlLog log = new ControlLog();
		log.setOperRecord(operRecord);
		log.setResult(result);
		log.setServiceModule(serviceModule);
		if (StringUtils.isBlank(operBy)) {
			log.setOperBy(SecurityUtils.getUser().getUsername());
			log.setCreateBy(SecurityUtils.getUser().getUsername());
			log.setUpdateBy(SecurityUtils.getUser().getUsername());
		}
		else {
			log.setOperBy(operBy);
			log.setCreateBy(operBy);
			log.setUpdateBy(operBy);
		}
		log.setCreateTime(LocalDateTime.now());
		log.setUpdateTime(LocalDateTime.now());
		return this.save(log);
	}

	/*@Override
	public List<ControlLogExcelVO> listControlLogByWhere(ControlLog ControlLog) {
		// LocalDateTime beginTime = ControlLog.getCreateTime();
		// LocalDateTime endTime = ControlLog.getUpdateTime();

		// ControlLog.setCreateTime(null);
		// ControlLog.setUpdateTime(null);
		List<ControlLog> logs = this.list(Wrappers.query(ControlLog));
		List<ControlLogExcelVO> listData = new ArrayList<>();
		for (ControlLog log : logs) {
			ControlLogExcelVO excelVO = new ControlLogExcelVO();
			BeanUtils.copyProperties(log, excelVO);
			listData.add(excelVO);
		}
		return listData;
	}*/

}
